<?php require_once("./includes/session.php"); ?>
<?php require_once("./includes/open_connection.php"); ?>
<?php require_once("./includes/functions.php"); ?>
<?php 
	$is_ajax = $_POST['is_ajax'];
	if(isset($is_ajax) && $is_ajax)
	{
		create_user($_POST['username'], $_POST['password'], $_POST['emailaddr'] );
	}
	// authenticate user
	else if(isset($_POST['submit']))
	{ // Form has been submitted.
		authenticate_user($_POST['username'], $_POST['password'] );
	}
	else 
	{
		// finding the current session
		session_start();
		
		// unsetting all session variables
		$_SESSION = array();
		
		// destroy the session cookie
		if(isset($_COOKIE[session_name()]))
		{
			setcookie(session_name(), '', time()-15000, '/');
		}
		
		// destroying session
		session_destroy();
		
		redirect_to("index.php?logout=1");
	}
?>